<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Check extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->library('session');
		$this->load->model('user_model');
	}

	function index()
	{
		echo json_encode(array('status' => 0));
	}

	/**
	 * 登陆验证
	 * @return [type] [description]
	 */
	function auth()
	{
		try {
			// 获取认证的结果
			$auth_result = $this->user_model->login($this->input->post());

			if ($auth_result['status'] == 1){
				$this->session->set_userdata('username',$auth_result['data']);
				echo json_encode(array('status' => 1));
			}else{
				echo json_encode(array('status' => 0));
			}	
		} catch (Exception $e) {
			// 认证失败，代码异常
			echo 'Error: 登陆验证失败', $e->getMessage();
		}
	}

	/**
	 * 注册用户
	 * @return [type] [description]
	 */
	function register()
	{
		try {
			// 获取注册的结果
			$reg_result = $this->user_model->register($this->input->post());

			echo json_encode($reg_result);
		} catch (Exception $e) {
			// 认证失败，代码异常
			echo 'Error: 注册失败', $e->getMessage();
		}
	}
}